package com.youdianda.controller;


import com.youdianda.dto.MenuDTO;
import com.youdianda.vo.MenuQueryVO;
import com.youdianda.result.Result;
import com.youdianda.service.ISysMenuService;
import com.youdianda.vo.MenuVO;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author mosen
 * @since 2023-05-15
 */
@RestController
@RequestMapping("/sys_menu")
@Slf4j
public class SysMenuController {

    @Autowired
    private ISysMenuService iSysMenuService;

    /**所有菜单*/
    @GetMapping("/allData")
    public Result<List<MenuQueryVO>> listAllMenu(){
        MenuQueryVO menuQueryVO = new MenuQueryVO();
        menuQueryVO.setId(0);
        List<MenuQueryVO> voList = iSysMenuService.listAllMenu(menuQueryVO);
        return Result.success(voList);
    }

    /**添加菜单*/
    @PostMapping("/add")
    public Result addMenu(@RequestBody MenuDTO menuDTO){
        return iSysMenuService.addMenu(menuDTO);
    }

    /**菜单详情*/
    @GetMapping("/rowInfo")
    public Result<MenuVO> getMenuById(@RequestParam(required = false) Integer id){
        return iSysMenuService.getMenuById(id);
    }

    /**菜单修改*/
    @PostMapping("/update")
    public Result updateMenu(@RequestBody MenuDTO menuDTO){
        iSysMenuService.update(menuDTO);
        return Result.success();
    }

    /**菜单删除*/
    @GetMapping("/del")
    public Result deleteMenu(@RequestParam Integer id){
        return iSysMenuService.deleteMenu(id);
    }

}
